import base64
from typing import List

import shortuuid
from peewee import JOIN

from afast_core.core_libs.captcha.cilent import generate_captcha
from afast_core.core_tools.generate_captcha_helper import generate_captcha_out_strmes_img
from afast_core.core_tools.jwt_helper import SimpleAuth
from infirmary_admin_src.infirmary_common.infirmary_controller import IAsyncSessionBaseController, IBaseController
from infirmary_admin_src.infirmary_common.infirmary_controller.rest_controller_with_depends import \
    RestControllerWithDepends
from fastapi import Request, Depends
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.schemas import SchemaBase




class XParam(SchemaBase):
    '''
    账号密码登录参数
    '''

class IController(IBaseController):
    '''
    定制相关约束检测函数逻辑步序
    '''

    def __init__(self, *, request: Request,
                 ):
        super().__init__(request=request)
        # 入参参数





@RestControllerWithDepends()
class CommonCaptchaImgController(IController):

    def business_login(self):
        pass
        # 生成验证码
        random_str, image_data = generate_captcha_out_strmes_img(w=120,h=60)
        base64_data = str(base64.b64encode(image_data), "utf-8")  # 使用base64进行加密
        # request.session["session_code"] = random_str.lower()
        captchaUuid = shortuuid.uuid()
        #记录到缓存中，便于进行检测验证码

        self.request.app.cache_house.set_key(captchaUuid,random_str.upper(),exp=60)
        return {
            'captchaUuid':captchaUuid,
            'captchaBase64Image':f"data:image/png;base64,{base64_data}",
            'captchaText':None,
            'expireSeconds':65,

        }